@namespace DaoHang.Components.Pages.AIRecommendation
@using DaoHang.Components.Shared
@using DaoHang.Models
@using DaoHang.Services

<div class="recommendation-item @(IsSelected ? "selected" : "")">
    <div class="item-header">
        <div class="website-info">
            <WebsiteIcon IconUrl="@Website.IconUrl" 
                        AltText="@Website.Name" 
                        CssClass="recommendation-icon" />
            <div class="website-meta">
                <h4 class="website-name">
                    <a href="@Website.Url" target="_blank">@Website.Name</a>
                    @if (Website.IsChineseWebsite)
                    {
                        <span class="website-badge chinese">
                            <i class="bi bi-geo-alt-fill"></i> 中国网站
                        </span>
                    }
                    <span class="website-badge score">
                        <i class="bi bi-star-fill"></i> @Website.Score.ToString("F1")
                    </span>
                </h4>
                <div class="website-url">
                    <a href="@Website.Url" target="_blank" class="text-truncate">@Website.Url</a>
                </div>
            </div>
        </div>
        <div class="website-actions">
            <div class="form-check">
                <input class="form-check-input" type="checkbox" id="check_@Website.Id" 
                       checked="@IsSelected" @onchange="OnSelectionChanged" />
                <label class="form-check-label" for="check_@Website.Id">
                    选择
                </label>
            </div>
        </div>
    </div>
    <div class="item-body">
        <p class="website-description">@Website.Description</p>
        @if (!string.IsNullOrEmpty(Website.Tags))
        {
            <div class="website-tags">
                @foreach (var tag in Website.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries))
                {
                    <span class="badge bg-light text-dark">@tag.Trim()</span>
                }
            </div>
        }
    </div>
</div>

@code {
    /// <summary>
    /// 网站对象
    /// </summary>
    [Parameter]
    public RecommendedWebsite Website { get; set; } = new();

    /// <summary>
    /// 是否被选中
    /// </summary>
    [Parameter]
    public bool IsSelected { get; set; }

    /// <summary>
    /// 选择状态变更回调
    /// </summary>
    [Parameter]
    public EventCallback<bool> OnSelectionChange { get; set; }

    /// <summary>
    /// 处理选择状态变更
    /// </summary>
    /// <param name="e">事件参数</param>
    private async Task OnSelectionChanged(ChangeEventArgs e)
    {
        if (e.Value is bool value)
        {
            IsSelected = value;
            await OnSelectionChange.InvokeAsync(value);
        }
    }
} 